[id].vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. <template>
  2. <div>
  3. <!-- 页面头部 -->
  4. <HomePageHead></HomePageHead>
  5. <HomePageNavigation1></HomePageNavigation1>
  6. <!-- 商圈详情 -->
  7. <div class="topicInfoBox">
  8. <div class="inner">
  9. <!-- 详情头部 -->
  10. <div class="infoHead">
  11. <div class="left">
  12. <div class="userInfo left">
  13. <el-badge value="楼主" class="item" type="warning">
  14. <img v-if='dataInfo.avatar' :src="dataInfo.avatar" alt="">
  15. <img v-else src='../../public/topic/Rectangle.png' alt="">
  16. </el-badge>
  17. <span>{{ dataInfo.nickname }}</span>
  18. </div>
  19. <div class="headContent left">
  20. <h2>{{ dataInfo.title }}</h2>
  21. <p v-show="dataInfo.group_name">
  22. 群聊:
  23. <span>{{ dataInfo.group_name }}</span>
  24. <button @click="joinGroup">加入群聊</button>
  25. </p>
  26. </div>
  27. </div>
  28. <div class="right">
  29. <div class="one">
  30. <span v-for="item in typeList" :key="index">
  31. <span v-if="dataInfo.type == item.value" class="one">{{item.label}}</span>
  32. </span>
  33. </div>
  34. <p>{{ dataInfo.updated_at }}</p>
  35. </div>
  36. </div>
  37. <!-- 详情页 文本+图片 -->
  38. <div class="infoContent" v-show="dataInfo.content">
  39. <div v-html="dataInfo.content"></div>
  40. </div>
  41. <div class="infoContent1" v-show="!dataInfo.content">
  42. <img src="../../public/topic/Document_empty.png" alt="">
  43. <span>可以看看大家的互动哦~</span>
  44. </div>
  45. <!-- 详情页评论 -->
  46. <div class="comment">
  47. <h3>评论</h3>
  48. <div class="commentList" v-for="item in replyList" v-show="page_total != 0">
  49. <div class="left">
  50. <img v-if='item.avatar' :src="item.avatar" alt="" >
  51. <img v-else src='../../public/topic/Rectangle.png' alt="">
  52. <span class="name">{{ item.nickname }} : </span>
  53. </div>
  54. <div class="center">
  55. <span class="context">{{ item.content }}</span>
  56. </div>
  57. <div class="right">
  58. <span class="time">{{ item.created_at }}</span>
  59. <!-- <span>回复</span> -->
  60. </div>
  61. </div>
  62. <div class="comment_empty" v-show="page_total == 0">
  63. <img src="../../public/topic/message_empty.png" alt="">
  64. <span>暂无评论</span>
  65. </div>
  66. </div>
  67. <!-- 分页 -->
  68. <div class="paginationBox" v-show="page_total != 0">
  69. <el-pagination background layout="prev, pager, next" :total="page_total" prev-text="上一页"
  70. next-text="下一页" :default-page-size="pageSize" @change="changePage" />
  71. </div>
  72. </div>
  73. </div>
  74. <div class="message">
  75. <div class="inner">
  76. <input v-model="content" placeholder="快来回复吧~" type="text" class="messageInput">
  77. <button class="btn" @click="addReply">确定</button>
  78. </div>
  79. </div>
  80. <!-- 页面底部 -->
  81. <HomeFoot1></HomeFoot1>
  82. </div>
  83. </template>
  84. <script setup>
  85. //1.引用模块 start ---------------------------------------->
  86. //使用ref和reactive动态变量
  87. import { ref, reactive, onMounted } from 'vue'
  88. import { useRoute } from 'vue-router';
  89. //使用官方ssr请求模块
  90. import { useNuxtApp, useFetch } from '#app'
  91. //使用element-plus组件
  92. import { ElPagination, ElBadge, ElInput, ElMessage, ElMessageBox } from 'element-plus';
  93. // axios请求
  94. const nuxtApp = useNuxtApp();
  95. const axios = nuxtApp.$axios;
  96. //1.引用模块 end ---------------------------------------->
  97. // 定义响应式数据
  98. const seoData = ref({
  99. title: '商圈',
  100. description: '默认描述',
  101. keywords: '默认关键词',
  102. image: 'https://example.com/default-image.jpg'
  103. });
  104. // 在 onMounted 钩子中获取数据
  105. onMounted(()=>{
  106. seoData.value.title = '商圈';
  107. seoData.value.description = '默认描述';
  108. seoData.value.keywords = '默认关键词';
  109. })
  110. //2.页面数据 start ---------------------------------------->
  111. const dataInfo = ref({})
  112. const groupId = useState("groupId", () => '')
  113. const replyList = useState("replyList", () => []) //评论列表
  114. //分页
  115. const page = ref(1)
  116. const pageSize = ref(5)
  117. let page_total = ref(0)
  118. const content = ref('')
  119. //2.页面数据 end ---------------------------------------->
  120. //3.获取商圈详情 start ---------------------------------------->
  121. const route = useRoute();
  122. const id = route.params.id; // 获取传递的 id 参数
  123. //页码发生改变
  124. const changePage = (val) => {
  125. console.log(val);
  126. page.value = val
  127. getTopicReply()
  128. }
  129. // 商圈信息
  130. const getTopicInfo = () => {
  131. let data = new FormData()
  132. data.append('id', id)
  133. axios.post('chat/getTopicInfo', data).then(res => {
  134. console.log('商圈信息', res);
  135. dataInfo.value = res.data
  136. groupId.value = res.data.group_id
  137. console.log(groupId.value);
  138. })
  139. }
  140. // 回复商圈 列表
  141. const getTopicReply = () => {
  142. let data = new FormData()
  143. data.append('id', id)
  144. data.append('page', page.value)
  145. data.append('page_size', pageSize.value)
  146. axios.post('chat/getTopicReply', data).then(res => {
  147. console.log('回复商圈列表 ', res);
  148. replyList.value = res.data.data
  149. // page_total.value = res.data.total
  150. page_total.value = res.data.total
  151. console.log("replyList", replyList);
  152. })
  153. }
  154. //5.获取分类和状态 start ---------------------------------------->
  155. const listData = useState("listData", () => [])//商圈列表
  156. const typeList = useState("typeList", () => [])//商圈分类
  157. const topicType = () => {
  158. axios.post('/chat/topicType').then(response => {
  159. console.log(111222333)
  160. console.log(response.data);
  161. // console.log(1);
  162. typeList.value = response.data;
  163. })
  164. }
  165. const topicStatus = () => {
  166. axios.post('chat/topicStatus').then(response => {
  167. console.log(response);
  168. })
  169. }
  170. onMounted(() => {
  171. getTopicInfo(); //商圈信息
  172. getTopicReply(); //回复商圈列表
  173. topicType();
  174. topicStatus();
  175. })
  176. //加入群聊
  177. const joinGroup = () => {
  178. ElMessageBox.confirm(
  179. '加入群聊后,页面跳转至后台群聊页面',
  180. '是否加入群聊?',
  181. {
  182. confirmButtonText: '是',
  183. cancelButtonText: '否',
  184. center: true,
  185. }
  186. ).then(() => {
  187. console.log('groupId.value', groupId.value);
  188. let data = new FormData()
  189. data.append('group_id', groupId.value)
  190. axios.post('chat/joinGroup', data).then(res => {
  191. console.log('加入群聊 ', res);
  192. if (res.code == 0 && res.message !== '已加入群') {
  193. ElMessage.error(res.message)
  194. } else if (res.code == 0 && res.message == '已加入群') {
  195. ElMessage({
  196. message: res.message,
  197. type: 'success',
  198. })
  199. setTimeout(() => {
  200. window.open('http://admindev.bjzxtw.org.cn/#/hall', '_blank');
  201. }, 1000)
  202. } else if (res.code == 200) {
  203. ElMessage({
  204. message: '加入成功',
  205. type: 'success',
  206. })
  207. setTimeout(() => {
  208. window.open('http://admindev.bjzxtw.org.cn/#/hall', '_blank');
  209. }, 1000)
  210. }
  211. })
  212. }).catch(() => {
  213. ElMessage({
  214. type: 'error',
  215. message: '已取消',
  216. })
  217. })
  218. }
  219. // 回复商圈
  220. const addReply = () => {
  221. let data = new FormData()
  222. data.append('id', id)
  223. data.append('content', content.value)
  224. axios.post('chat/addReply', data).then(res => {
  225. console.log('回复商圈 ', res);
  226. if (res.code == 0) {
  227. ElMessage.error(res.message)
  228. getTopicReply();
  229. } else if (res.code == 200) {
  230. ElMessage({
  231. message: '回复成功',
  232. type: 'success',
  233. })
  234. content.value = ''
  235. getTopicReply();
  236. }
  237. })
  238. }
  239. //3.获取商圈详情 end ---------------------------------------->
  240. </script>
  241. <style lang="less" scoped>
  242. .topicInfoBox {
  243. .inner {
  244. width: 1200px;
  245. margin: 0 auto;
  246. //信息头部
  247. .infoHead {
  248. height: 200px;
  249. padding: 65px 0 60px 40px;
  250. border-bottom: 1px solid rgba(0, 0, 0, 0.10);
  251. box-sizing: border-box;
  252. >.left {
  253. .userInfo {
  254. margin-right: 90px;
  255. .item {
  256. margin-top: -5px;
  257. margin-right: -5px;
  258. :deep(.el-badge__content.is-fixed) {
  259. position: absolute;
  260. right: calc(1px + var(--el-badge-size) / 2);
  261. top: 0;
  262. transform: translateY(-31%) translateX(79%);
  263. z-index: var(--el-index-normal);
  264. }
  265. img {
  266. width: 66px;
  267. height: 66px;
  268. vertical-align: middle;
  269. border-radius: 50%;
  270. }
  271. }
  272. span {
  273. margin-left: 15px;
  274. font-family: Microsoft YaHei, Microsoft YaHei;
  275. font-weight: 400;
  276. font-size: 18px;
  277. color: #333333;
  278. }
  279. }
  280. .headContent {
  281. h2 {
  282. width: 750px;
  283. height: 56px;
  284. line-height: 28px;
  285. display: -webkit-box;
  286. -webkit-box-orient: vertical;
  287. -webkit-line-clamp: 2;
  288. overflow: hidden;
  289. text-overflow: ellipsis;
  290. word-break: break-all;
  291. font-family: Microsoft YaHei, Microsoft YaHei;
  292. font-weight: bold;
  293. font-size: 20px;
  294. color: #333333;
  295. margin-bottom: 26px;
  296. }
  297. >p {
  298. font-family: Microsoft YaHei, Microsoft YaHei;
  299. font-weight: 400;
  300. font-size: 16px;
  301. color: #333333;
  302. button {
  303. width: 86px;
  304. height: 32px;
  305. background-color: #028e21;
  306. color: #fff;
  307. border: none;
  308. margin-left: 100px;
  309. }
  310. }
  311. }
  312. }
  313. >.right {
  314. position: relative;
  315. div {
  316. position: absolute;
  317. right: 0;
  318. top: 0;
  319. width: 71px;
  320. height: 32px;
  321. line-height: 32px;
  322. text-align: center;
  323. background-color: #d9f0d6;
  324. margin-bottom: 29px;
  325. font-family: Microsoft YaHei, Microsoft YaHei;
  326. font-weight: 400;
  327. font-size: 16px;
  328. color: #33B023;
  329. }
  330. .one {
  331. color: #FFAA33;
  332. background-color: #fbebd5;
  333. }
  334. .two {
  335. color: #33B023;
  336. background-color: #d5ecd2;
  337. }
  338. .three {
  339. color: #666;
  340. background-color: #ebebeb;
  341. }
  342. p {
  343. width: 150px;
  344. text-align: right;
  345. position: absolute;
  346. top: 62px;
  347. right: 0;
  348. }
  349. }
  350. }
  351. // 有详情信息
  352. .infoContent {
  353. width:1196px;
  354. overflow: hidden;
  355. padding: 40px 46px;
  356. font-family: Microsoft YaHei, Microsoft YaHei;
  357. font-size: 20px;
  358. line-height: 40px;
  359. box-sizing: border-box;
  360. div{
  361. word-wrap: break-word; /* 强制长单词或 URL 换行 */
  362. overflow-wrap: break-word; /* 现代推荐用法,等同于 word-wrap */
  363. white-space: pre-wrap; /* 保留空白字符并允许自动换行 */
  364. word-break: break-all; /* 强制在任意字符处换行 */
  365. }
  366. }
  367. .leftBottom::v-deep p{
  368. width:1200px;
  369. white-space: pre-wrap;
  370. }
  371. //没有详情信息
  372. .comment_empty,
  373. .infoContent1 {
  374. height: 300px;
  375. line-height: 260px;
  376. text-align: center;
  377. img {
  378. width: 78px;
  379. height: 78px;
  380. vertical-align: -25px;
  381. vertical-align: middle;
  382. margin-right: 20px;
  383. }
  384. span {
  385. font-family: Microsoft YaHei, Microsoft YaHei;
  386. font-weight: bold;
  387. font-size: 26px;
  388. color: #CCCCCC;
  389. }
  390. }
  391. //评论
  392. .comment {
  393. h3 {
  394. height: 100px;
  395. padding-top: 30px;
  396. box-sizing: border-box;
  397. border-bottom: 1px solid #E1E1E1;
  398. font-family: Microsoft YaHei, Microsoft YaHei;
  399. font-weight: 400;
  400. font-size: 22px;
  401. color: #000000;
  402. }
  403. .commentList {
  404. // height: 112px;
  405. border: 1px solid #E1E1E1;
  406. background-color: #fafafa;
  407. margin-top: 20px;
  408. padding: 30px 30px;
  409. box-sizing: border-box;
  410. display: flex;
  411. align-items: flex-start;
  412. justify-content: space-between;
  413. .left {
  414. width:400px;
  415. margin-right: 40px;
  416. // overflow: hidden;
  417. display: flex;
  418. justify-content: space-between;
  419. img {
  420. // float: left;
  421. width: 52px;
  422. height: 52px;
  423. border-radius: 50%;
  424. vertical-align: middle;
  425. margin-right: 15px;
  426. }
  427. span{
  428. // float: left;
  429. height: 52px;
  430. line-height: 22px;
  431. padding-top: 10px;
  432. }
  433. .name {
  434. width: 100px;
  435. font-family: Microsoft YaHei, Microsoft YaHei;
  436. font-weight: 400;
  437. font-size: 16px;
  438. color: #333333;
  439. margin-right: 30px;
  440. width: 100px;
  441. white-space: nowrap;
  442. overflow: hidden;
  443. text-overflow: ellipsis;
  444. display: block;
  445. }
  446. }
  447. .center {
  448. .context {
  449. width: 700px;
  450. margin-right: 40px;
  451. display: -webkit-box;
  452. -webkit-box-orient: vertical;
  453. -webkit-line-clamp: 2;
  454. overflow: hidden;
  455. text-overflow: ellipsis;
  456. word-break: break-all;
  457. font-family: Microsoft YaHei, Microsoft YaHei;
  458. font-weight: bold;
  459. font-size: 16px;
  460. color: #333333;
  461. }
  462. }
  463. .right {
  464. .time {
  465. display: block;
  466. width: 200px;
  467. font-family: Microsoft YaHei, Microsoft YaHei;
  468. font-weight: 400;
  469. font-size: 16px;
  470. color: #999999;
  471. margin-right: 30px;
  472. }
  473. span {
  474. font-family: Microsoft YaHei, Microsoft YaHei;
  475. font-weight: 400;
  476. font-size: 16px;
  477. color: #333333;
  478. }
  479. }
  480. }
  481. // .comment_empty {
  482. // height: 200px;
  483. // line-height: 200px;
  484. // text-align: center;
  485. // img {
  486. // width: 78px;
  487. // height: 78px;
  488. // vertical-align: -25px;
  489. // margin-right: 20px;
  490. // }
  491. // span {
  492. // font-family: Microsoft YaHei, Microsoft YaHei;
  493. // font-weight: bold;
  494. // font-size: 26px;
  495. // color: #CCCCCC;
  496. // }
  497. // }
  498. }
  499. }
  500. }
  501. //评论回复
  502. .message {
  503. width: 1200px;
  504. margin: 0 auto;
  505. padding: 0px 25px;
  506. box-sizing: border-box;
  507. height: 145px;
  508. line-height: 145px;
  509. background-color: #ecf5ee;
  510. .inner {
  511. .messageInput {
  512. width: 1000px;
  513. height: 67px;
  514. outline: none;
  515. border: 1px solid #E1E1E1;
  516. background-color: #fafafa;
  517. font-family: Microsoft YaHei, Microsoft YaHei;
  518. font-weight: 400;
  519. font-size: 18px;
  520. color: #666;
  521. padding: 0 20px;
  522. box-sizing: border-box;
  523. }
  524. .btn {
  525. width: 115px;
  526. height: 40px;
  527. border: none;
  528. background-color: #028e21;
  529. color: #fff;
  530. border-radius: 6px;
  531. margin-left: 36px;
  532. font-family: Microsoft YaHei, Microsoft YaHei;
  533. font-weight: 400;
  534. font-size: 16px;
  535. }
  536. }
  537. }
  538. //分页
  539. .paginationBox {
  540. display: flex;
  541. justify-content: center;
  542. margin-top: 60px;
  543. margin-bottom: 90px;
  544. // 鼠标移入后字体颜色
  545. :deep(.el-pagination:hover) {
  546. color: #139609;
  547. }
  548. :deep(.el-pagination.is-background .btn-next),
  549. :deep(.el-pagination.is-background .btn-prev) {
  550. width: 70px;
  551. height: 34px;
  552. margin: 0px 10px;
  553. border-radius: 4px;
  554. }
  555. :deep(.el-pagination.is-background .el-pager li) {
  556. margin: 0px 10px;
  557. width: 38px;
  558. height: 34px;
  559. border-radius: 4px;
  560. }
  561. :deep(.el-pagination.is-background .btn-next.is-active),
  562. :deep(.el-pagination.is-background .btn-prev.is-active),
  563. :deep(.el-pagination.is-background .el-pager li.is-active) {
  564. background-color: #028e21;
  565. color: #fff;
  566. }
  567. }
  568. </style>